<?php

namespace app\api\controller\xykeep;
use app\common\controller\Api;

use app\api\model\xykeep\Article as ArticleModel;
use app\api\model\xykeep\user\View as ViewModel;
use think\Config;

/**
 * XYkeep文章接口
 */
class Article extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    
	/**
	 * 文章列表
	 */
	public function lists()
    {
        $store_id = input('store_id/d',0);
        $limit = input('limit/d',4);
        $data = ArticleModel::getLists($store_id,$limit);
        $this->success('文章列表', $data);
    }
	
    /**
     * 文章详情
     */
    public function detail()
    {
        $id = $this->request->get('id');
        $detail = ArticleModel::getDetail($id);
        $detail['createtime'] = date('Y-m-d H:i:s',$detail['createtime']);

        if(!$detail){
            $this->error('文章不存在！');
        }

        // 记录足记
        ViewModel::addView($detail,'article');

        $this->success('文章详情', $detail);
    }


    /**
     * 其他
     */
    public function other()
    {
        $type = $this->request->get('type');
        $info = [];
        if($type=='company'){
            $info['title'] = '关于我们';
            $info['content'] = Config::get('site.about_us');
        }else if($type=='privacy'){
            $info['title'] = '隐私协议';
            $info['content'] = Config::get('site.privacy');
        }else if($type=='agreement'){
            $info['title'] = '用户协议';
            $info['content'] = Config::get('site.agreement');
        }else if($type=='question') {
            $info['title'] = '常见问题';
            $info['content'] = Config::get('site.question');
        }
        $this->success('其他',$info);
    }
}